package com.jboltai.event.chain;

import com.jboltai.config.JBoltAIConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CommonChainNode extends ChainNode<CommonChainNode>{

    private static final Logger LOGGER = LoggerFactory.getLogger(JBoltAIConfig.LOGGER_NAME);
    private CommonHandler commonHandler;

    public CommonChainNode(CommonHandler commonHandler) {
        this.commonHandler = commonHandler;
    }

    public CommonChainNode(String id, CommonHandler commonHandler) {
        this.commonHandler = commonHandler;
        this.id = id;
    }

    @Override
    protected void execute() {
        try {

            commonHandler.handle(chain);
            this.success();
        } catch (Exception e) {
            LOGGER.error("CommonChainNode类型节点执行过程中发生异常", e);
            this.fail(e.getMessage(), e);

        }
    }

    public CommonHandler getCommonHandler() {
        return commonHandler;
    }
}
